/**
 * 
 */
package pyrachnid.view.component;

import java.io.File;
import java.io.IOException;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileSystemView;

import pyrachnid.ctrl.Simulator;

/**
 * @author zygou
 *
 */
public class MapFileChooser extends JFileChooser {

	private static final long serialVersionUID = 6331589352780180919L;
	
	private Simulator _simu;
	
	public MapFileChooser(Simulator simu){
		super();
		_simu = simu;
		setCurrentDirectory(new File("./images/images/maps"));
		setMultiSelectionEnabled(false);
		setAcceptAllFileFilterUsed(false);
		addChoosableFileFilter(new MapFileFilter());
		setAccessory(new MapPreview(this));
		setFileSystemView(FileSystemView.getFileSystemView());
	}

	@Override
	public void approveSelection(){	

		try {
			MapDimDial mapDial = new MapDimDial(_simu,getSelectedFile());
			if(mapDial.display() == MapDimDial.VALIDATED) super.approveSelection();
		} catch (IOException e) {}

	    return;
	}	
}
